<div class="form">
<?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm',array(
	'id'=>'wewenang-authitem-form',
	'enableAjaxValidation'=>false,
        'method'=>'post',
	'type'=>'horizontal',
	'htmlOptions'=>array(
		'enctype'=>'multipart/form-data'
	)
)); ?>
    <!--fieldset><legend><p class="note">Fields with <span class="required">*</span> are required.</p></legend-->

    <div class="feedbackbox">
	<?php echo $form->errorSummary($model); ?>

    <div class="control-group">
        <label class="control-label">Nama <span class="required">*</span></label>
        <div class="controls">
            <?php echo $form->textField($model,'name',array('size'=>60,'maxlength'=>64)); ?>
            <?php echo $form->error($model,'name'); ?>
        </div>

        <label class="control-label">Deskripsi</label>
        <div class="controls">
            <?php echo $form->textArea($model,'description',array('rows'=>2, 'cols'=>150, 'class'=>'span7')); ?>
            <?php echo $form->error($model,'description'); ?>
        </div>
    </div>
    </div>
	<?php /*<div class="row">
		<?php echo $form->textFieldRow($model,'name',array('size'=>60,'maxlength'=>64)); ?>
		<?php echo $form->error($model,'name'); ?>
	</div>

        <div class="row">
		<?php echo $form->textAreaRow($model,'description',array('rows'=>6, 'cols'=>50)); ?>
		<?php echo $form->error($model,'description'); ?>
	</div>
    </div> */ ?>
        
     <!--/fieldset-->

        <!--div class="row"-->
        <!-- start of first grid -->
        <div class="div-dbkb">
	<div class="div-fontdbkb">Daftar User</div>
	<fieldset class="fieldsetDBKB">
            <?php
                $dataProvider=User::model()->searchByAuthItem($model->name);
                $this->widget('bootstrap.widgets.TbGridView', array(
                    'id'=>'authitemuser-grid',
                    'dataProvider'=>$dataProvider,
                    'type'=>'striped bordered condensed',
                    'template'=>'{items}{pager}',
                    'selectableRows'=>2,
                    'columns'=>array(
                        array(
                            'id'=>'selectUser',
                            'class'=>'CCheckBoxColumn',                            
                            'value'=>'$data->id',
                            'checked'=>'$data->wewenang',
                            'checkBoxHtmlOptions' => array( "ajax" => 
                                                     array("type"=>"POST", 
                                                       "url"=>CController::createUrl("Authitem/checkExistRole"),
                                                       "data"=>array("elmid"=>"js:$(this).attr('id')","elmval"=>"js:$(this).attr('value')"),
                                                       "dataType"=>"json",
                                                       "success"=>"function(data){
                                                            if(data.allowed==false)
                                                                alert('Tidak bisa memilih username ini karena sudah merupakan anggota dari role = '+data.role);
                                                            $(data.elmid).attr('checked',data.allowed);
                                                            }",
                                                     ),
                
                                                )
                        ),
                        array(
                            'name'=>'username',
                            'header'=>'Username',
                            'htmlOptions'=>array('style'=>'width:30%')
                        ),
                        /*
                        array(
                            'name'=>'nip',
                            'header'=>'NIP',
                            'htmlOptions'=>array('style'=>'width:30%'),
                        ),
                        */
                        array(
                           'name' => 'nama',
                           'value' => '$data->nama',
                         
                        ),   
                    ),
                ));
            ?>
        </fieldset>
        </div>
        <!-- end of first grid -->
        <!--/div-->
        
        <!--div class="row">List Menu</div-->
        <!--div class="row"-->
        <!-- start of second grid -->
        <div class="div-dbkb">
	<div class="div-fontdbkb">Daftar Menu <?php echo $model->name; ?></div>
	<fieldset class="fieldsetDBKB">
            <?php
                $this->widget('bootstrap.widgets.TbGridView', array(
                    'id'=>'authitem-grid',
                    'enablePagination' => false,
                    'dataProvider'=>$model->findOperationByRoleName($model->name),
                    'type'=>'striped bordered condensed',
                    'template'=>'{items}{pager}',
                    'htmlOptions'=>array('style'=>'overflow-y:scroll;max-height:351px;'),
                    'columns'=>array(
                        array(
                            'name'=>'menuname',
                            'header'=>'Menu',
                        ),
                        array(
                            'id'=>'selectView',
                            'class'=>'CCheckBoxColumn',
                            'checked'=>'$data[Authitem::OPERATION_TYPE_INDEX2]',
                            'value'=>'$data["controllername"]',
                            'selectableRows'=>2,
                            'headerHtmlOptions'=>array('nowrap'=>'true'),
                            'headerTemplate'=>'<div>{item} Lihat</div>'
                        ),
                        array(
                            'id'=>'selectCreate',
                            'class'=>'CCheckBoxColumn',
                            'checked'=>'$data[Authitem::OPERATION_TYPE_CREATE]',
                            'value'=>'$data["controllername"]',
                            'selectableRows'=>2,
                            'headerHtmlOptions'=>array('nowrap'=>'true'),
                            'headerTemplate'=>'<div>{item} Tambah</div>'
                        ),
                        array(
                            'id'=>'selectUpdate',
                            'class'=>'CCheckBoxColumn',
                            'checked'=>'$data[Authitem::OPERATION_TYPE_UPDATE]',
                            'value'=>'$data["controllername"]',
                            'selectableRows'=>2,
                            'headerHtmlOptions'=>array('nowrap'=>'true'),
                            'headerTemplate'=>'<div>{item} Ubah</div>'  
                        ),
                        array(
                            'id'=>'selectDelete',
                            'class'=>'CCheckBoxColumn',
                            'checked'=>'$data[Authitem::OPERATION_TYPE_DELETE]',
                            'value'=>'$data["controllername"]',
                            'selectableRows'=>2,
                            'headerHtmlOptions'=>array('nowrap'=>'true'),
                            'headerTemplate'=>'<div>{item} Hapus</div>'
                        ),
                        array(
                            'id'=>'selectPosting',
                            'class'=>'CCheckBoxColumn',
                            'checked'=>'$data[Authitem::OPERATION_TYPE_POSTING]',
                            'value'=>'$data["controllername"]',
                            'selectableRows'=>2,
                            'headerHtmlOptions'=>array('nowrap'=>'true'),
                            'headerTemplate'=>'<div>{item} Posting</div>',
                        ),
                        
                    ),
                ));
            ?>
            
            <?php 
                /*$this->widget('EScrollableGridView',array(
                    'id'=>'authitem-grid',
                    'height' => '500',
                    'width' => '700',
                    'flush' => false,
                    'dataProvider'=>$model->findOperationByRoleName($model->name),
                    //'type'=>'striped bordered condensed',
                    'columns'=>array(
                        array(
                            'name'=>'modulename',
                            'header'=>'Menu',
                        ),
                        array(
                            'id'=>'selectView',
                            'class'=>'CCheckBoxColumn',
                            'checked'=>'$data[Authitem::OPERATION_TYPE_INDEX]',
                            'value'=>'$data["modulename"]',
                            'selectableRows'=>2,
                            'headerHtmlOptions'=>array('nowrap'=>'true'),
                            'headerTemplate'=>'<div>{item} Lihat</div>'
                        ),
                        array(
                            'id'=>'selectCreate',
                            'class'=>'CCheckBoxColumn',
                            'checked'=>'$data[Authitem::OPERATION_TYPE_CREATE]',
                            'value'=>'$data["modulename"]',
                            'selectableRows'=>2,
                            'headerHtmlOptions'=>array('nowrap'=>'true'),
                            'headerTemplate'=>'<div>{item} Tambah</div>'
                        ),
                        array(
                            'id'=>'selectUpdate',
                            'class'=>'CCheckBoxColumn',
                            'checked'=>'$data[Authitem::OPERATION_TYPE_UPDATE]',
                            'value'=>'$data["modulename"]',
                            'selectableRows'=>2,
                            'headerHtmlOptions'=>array('nowrap'=>'true'),
                            'headerTemplate'=>'<div>{item} Ubah</div>'  
                        ),
                        array(
                            'id'=>'selectDelete',
                            'class'=>'CCheckBoxColumn',
                            'checked'=>'$data[Authitem::OPERATION_TYPE_DELETE]',
                            'value'=>'$data["modulename"]',
                            'selectableRows'=>2,
                            'headerHtmlOptions'=>array('nowrap'=>'true'),
                            'headerTemplate'=>'<div>{item} Hapus</div>'
                        ),
                        
                    ),
                ));*/
            ?>
        </fieldset>
        </div>
        <!-- end of second grid -->
        
        <div class="row buttons">            
		<?php echo CHtml::submitButton($model->isNewRecord ? 'Tambah' : 'Simpan',array('class'=>'btn btn-primary','style'=>'width:120px;')); ?>
	</div>

<?php $this->endWidget(); ?>
</div><!-- form -->